package com.kara.woodAgent.agent.tool;

import com.kara.woodAgent.agent.tool.provider.McpTool;
import com.kara.woodAgent.agent.tool.provider.Tools;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.mcp.client.DefaultMcpClient;
import dev.langchain4j.mcp.client.McpClient;
import dev.langchain4j.mcp.client.transport.McpTransport;
import dev.langchain4j.mcp.client.transport.http.HttpMcpTransport;
import dev.langchain4j.mcp.client.transport.stdio.StdioMcpTransport;
import dev.langchain4j.web.search.WebSearchOrganicResult;
import dev.langchain4j.web.search.WebSearchRequest;
import dev.langchain4j.web.search.WebSearchResults;
import dev.langchain4j.web.search.tavily.TavilyWebSearchEngine;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author tzy
 * @version 1.0
 * @project wood_agent
 * @description
 * @date 2025/6/4 09:08:31
 */
@Tools(groups = "search")
@Component
public class SearchTools {


	@Value("${model.baidu.apiKey}")
	private String apiKey;


	@McpTool(enable = true)
	public McpClient zhipuSearch() {

		McpTransport transport = new HttpMcpTransport.Builder()
				.sseUrl("http://appbuilder.baidu.com/v2/ai_search/mcp/sse?api_key=Bearer+"+apiKey)
				.logRequests(true) // 如果你想在日志中查看流量
				.logResponses(true)
				.build();


		return new DefaultMcpClient.Builder()
				.transport(transport)
				.build();
	}


	@McpTool(enable = false)
	public McpClient browserUse() {

		McpTransport transport = new StdioMcpTransport.Builder()
				.command(List.of("npx", "@agent-infra/mcp-server-browser@latest"))
				.logEvents(true) // 仅当你想在日志中查看流量时
				.build();

		return new DefaultMcpClient.Builder()
				.transport(transport)
				.build();
	}


}
